﻿using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public static class NguoiDungDAO
    {

        public static SqlDataReader SelectAll()
        {
            return SqlHelper.ExecuteReader(ConnectionString.Text, CommandType.StoredProcedure, "sp_NguoiDung_SelectAll");
        }
        public static int Count_ALL()
        {
            return (int)SqlHelper.ExecuteScalar(ConnectionString.Text, CommandType.StoredProcedure, "sp_NguoiDung_CountAll");
        }
        /// <summary>
        /// Inserts the specified onguoidung.
        /// </summary>
        /// <param name="onguoidung">The onguoidung.</param>
        public static void Insert(NguoiDungDTO onguoidung)
        {
            var param = new SqlParameter[5];
            param[0] = new SqlParameter("@TenDN", onguoidung.TenDN);
            param[1] = new SqlParameter("@MatKhau", onguoidung.MatKhau);
            param[2] = new SqlParameter("@HoTen", onguoidung.HoTen);
            param[3] = new SqlParameter("@NgaySinh", onguoidung.NgaySinh);
            param[4] = new SqlParameter("@GioiTinh", onguoidung.GioiTinh);

            SqlHelper.ExecuteNonQuery(ConnectionString.Text, "sp_nguoidung_Insert", param);
        }

        /// <summary>
        /// Logins the specified TXT user.
        /// </summary>
        /// <param name="txtUser">The TXT user.</param>
        /// <param name="txtPass">The TXT pass.</param>
        /// <returns></returns>
        public static SqlDataReader Login(string txtUser, string txtPass, string txtHoTen)
        {
            var param = new SqlParameter[3];
            param[0] = new SqlParameter("@TenDN", txtUser);
            param[1] = new SqlParameter("@MatKhau", txtPass);
            param[2] = new SqlParameter("@HoTen", txtHoTen);
            return SqlHelper.ExecuteReader(ConnectionString.Text, CommandType.StoredProcedure, "sp_login", param);
            //@"Server=ADMIN-PC;AttachDbFilename=|DataDirectory|CNPM.mdf;Database=CNPM; Trusted_Connection=Yes;"
        }
        public static void AttachFile()
        {
            SqlHelper.ExecuteNonQuery(
                @"Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|CNPM.mdf;Database=CNPM; Trusted_Connection=Yes;",
                CommandType.Text, "Select name from sys.sysdatabases");
        }
    }
}